package org.msfj.hospital.controller;

import org.msfj.hospital.model.HospitalNews;
import org.msfj.hospital.vo.HospitalNewsVo;
import org.msfj.hospital.service.HospitalNewsService;
import org.msfj.common.base.BaseController;
import org.msfj.common.model.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import com.github.pagehelper.PageInfo;
import java.util.List;

/**
 * @Description: 医院新闻信息controller
 * @Author: like
 * @Email: like@deyatong.com
 * @Date: 2018-08-21 15:01:20
 * @Version: 1.0
 * @Created in idea by autoCode
 */
@Api(value = "医院新闻信息接口", tags = "医院新闻信息接口")
@RestController
@RequestMapping("/hospitalNews/")
public class  HospitalNewsController extends BaseController{

    @Autowired
    private HospitalNewsService hospitalNewsService;

    /**
     * 添加医院新闻信息
     *
     * @param hospitalNewsVo
     * @return CommonResult.ok(HospitalNewsVo)
     */
    @PostMapping("/add")
    @ApiOperation(value = "添加医院新闻信息",notes = "添加医院新闻信息")
    @ApiImplicitParam(value = "hospitalNewsVo",name = "hospitalNewsVo",dataType = "org.msfj.hospital.vo.HospitalNewsVo",paramType = "query")
    public CommonResult addHospitalNews(HospitalNewsVo hospitalNewsVo){
        HospitalNews hospitalNews = hospitalNewsService.saveOrEdit(hospitalNewsVo);
        return CommonResult.ok(hospitalNewsService.setOtherProperties(hospitalNews));
    }

    /**
     * 修改医院新闻信息
     *
     * @param hospitalNewsVo
     * @return CommonResult.ok(HospitalNewsVo)
     */
    @PostMapping("/edit")
    @ApiOperation(value = "修改医院新闻信息",notes = "修改医院新闻信息")
    @ApiImplicitParam(value = "hospitalNewsVo",name = "hospitalNewsVo",dataType = "org.msfj.hospital.vo.HospitalNewsVo",paramType = "query")
    public CommonResult editHospitalNews(HospitalNewsVo hospitalNewsVo){
        HospitalNews hospitalNews = hospitalNewsService.saveOrEdit(hospitalNewsVo);
        return CommonResult.ok(hospitalNewsService.setOtherProperties(hospitalNews));
    }

    /**
     * 逻辑删除医院新闻信息
     *
     * @param hospitalNewsVo
     * @return CommonResult.ok(HospitalNewsVo)
     */
    @PostMapping("/del")
    @ApiOperation(value = "逻辑删除医院新闻信息",notes = "逻辑删除医院新闻信息")
    @ApiImplicitParam(value = "hospitalNewsVo",name = "hospitalNewsVo",dataType = "org.msfj.hospital.vo.HospitalNewsVo",paramType = "query")
    public CommonResult delHospitalNews(HospitalNewsVo hospitalNewsVo){
        HospitalNews hospitalNews = hospitalNewsService.delById(hospitalNewsVo);
        return CommonResult.ok(hospitalNewsService.setOtherProperties(hospitalNews));
    }

    /**
     * 逻辑删除系统用户信息
     * @param ids
     * @return CommonResult.ok()
     */
    @PostMapping("/dels")
    @ApiOperation(value = "逻辑删除医院新闻信息",notes = "逻辑删除医院新闻信息")
    @ApiImplicitParam(value = "ids[]",name = "ids[]",dataType = "java.util.List",paramType = "query")
    public CommonResult delSysUsers(@RequestParam(value = "ids[]",required = false) List<String> ids){
        HospitalNews hospitalNews = new HospitalNews();
        hospitalNewsService.delByIds(ids,hospitalNews);
        return CommonResult.ok();
    }

    /**
     * 真实删除医院新闻信息
     *
     * @param hospitalNewsVo
     * @return CommonResult.ok()
     */
    @PostMapping("/delete")
    @ApiOperation(value = "真实删除医院新闻信息",notes = "真实删除医院新闻信息")
    @ApiImplicitParam(value = "hospitalNewsVo",name = "hospitalNewsVo",dataType = "org.msfj.hospital.vo.HospitalNewsVo",paramType = "query")
    public CommonResult deleteHospitalNews(HospitalNewsVo hospitalNewsVo){
        hospitalNewsService.trueDelById(hospitalNewsVo);
        return CommonResult.ok();
    }

    /**
     * 根据id查找医院新闻信息
     *
     * @param hospitalNewsVo
     * @return CommonResult.ok(HospitalNewsVo)
     */
    @GetMapping("/get")
    @ApiOperation(value = "根据id查找医院新闻信息",notes = "根据id查找医院新闻信息")
    @ApiImplicitParam(value = "hospitalNewsVo",name = "hospitalNewsVo",dataType = "org.msfj.hospital.vo.HospitalNewsVo",paramType = "query")
    public CommonResult getHospitalNews(HospitalNewsVo hospitalNewsVo){
        HospitalNews hospitalNews = hospitalNewsService.getById(hospitalNewsVo.getId());
        return CommonResult.ok(hospitalNewsService.setOtherProperties(hospitalNews));
    }

    /**
     * 根据翻页参数、搜索参数查找医院新闻信息
     *
     * @param hospitalNewsVo
     * @param page 当前第几页
     * @param rows 每页多少条记录
     * @return CommonResult.ok(PageInfo<HospitalNewsVo>)
     */
    @GetMapping("/list")
    @ApiOperation(value = "根据翻页参数、搜索参数查找医院新闻信息",notes = "根据翻页参数、搜索参数查找医院新闻信息")
    @ApiImplicitParams({
        @ApiImplicitParam(value = "hospitalNewsVo",name = "hospitalNewsVo",dataType = "org.msfj.hospital.vo.HospitalNewsVo",paramType = "query"),
        @ApiImplicitParam(name = "page",value = "page",dataType = "Integer",paramType = "path"),
        @ApiImplicitParam(name = "rows",value = "rows",dataType = "Integer",paramType = "path")
    })
    public CommonResult findHospitalNewsList(HospitalNewsVo hospitalNewsVo, Integer page, Integer rows){
        PageInfo<HospitalNewsVo> hospitalNewsVoPageInfo = hospitalNewsService.getByHospitalNews(hospitalNewsVo,page,rows);
        return CommonResult.ok(hospitalNewsVoPageInfo);
    }

    /**
     * 根据搜索参数查找所有医院新闻信息
     *
     * @param hospitalNewsVo
     * @return CommonResult.ok(List<HospitalNewsVo>)
     */
    @GetMapping("/getAll")
    @ApiOperation(value = "根据搜索参数查找所有医院新闻信息",notes = "根据搜索参数查找所有医院新闻信息")
    @ApiImplicitParam(value = "hospitalNewsVo",name = "hospitalNewsVo",dataType = "org.msfj.hospital.vo.HospitalNewsVo",paramType = "query")
    public CommonResult getAllHospitalNews(HospitalNewsVo hospitalNewsVo){
        List<HospitalNewsVo> hospitalNewsVoList = hospitalNewsService.getAllHospitalNews(hospitalNewsVo);
        return CommonResult.ok(hospitalNewsVoList);
    }
}
